File Description
- i2c_sim.h: API header of i2c functions.
- i2c_sim.c: API implementation of i2c functions.
- fsl_mma8451.h: API header of MMA8451 functions.
- fsl_mma8451.h: API implementation of MMA8451 functions.
- mma8451_main.c: Main function that shows the values that read from MMA8451 driver.
- fxos8700cq.c: Main function that will use fxos8700cq library APIs to show sensor data.
Build
In K64 Freedom board demo, fxos8700cq is a library in boards/common which you need to build first.
HOWTO Customization
There are parameters that can be configured to meet another request.
Pin Selection
Pin selection on board:
| Function | TWR-Kinetis | FRDM-Kinetis |
| SCL | PTC10 | PTC11 |
| SDA | PTE24 | PTE25 |
GPIO_SCL_PORT and GPIO_SDA_PORT are used as SCL and SDA port index in I2C driver.
GPIO_SCL_PIN and GPIO_SDA_PIN are used as SCL and SDA PIN index in I2C driver.
These pins are used to connect GPIO as I2C to MMA8451 or FXOS8700CQ I2C interface PINs.
These four macros can be configured in i2c_sim.h.
#define GPIO_SCL_PORT BOARD_I2C_GPIO_SCL_PORT
#define GPIO_SDA_PORT BOARD_I2C_GPIO_SDA_PORT
#define GPIO_SCL_PIN BOARD_I2C_GPIO_SCL_PIN
#define GPIO_SDA_PIN BOARD_I2C_GPIO_SDA_PIN
Baudrate Configuration
To get the correct baudrate, use an oscilloscope to get correct waveform for a baudrate.
A delay is used in this demo application for a correct baudrate.
#define I2C_DELAY \
do \
{ \
int32_t i; \
for (i = 0; i < 500; i++) \
{ \
__asm("nop"); \
} \
} while (0)
For a higher baudrate, reduce the delay time and loop count.
For a lower baudrate, increase the delay time and loop count.Additionally, you must also consider code execution time.
Thus, it is recommended that you use an oscilloscope to get the correct waveform for a baudrate.
There is no delay in code execution in this demo application, therefore, this might be the highest baudrate.
Please read I2C protocal and MMA8451 chip details for more information.